//
//  HCHelpViewDsiplay.m
//  ibeaconDemo
//
//  Created by liyun on 14-7-16.
//  Copyright (c) 2014年 qkong. All rights reserved.
//

#import "HCHelpViewDsiplay.h"
#import "HCMacroDefinition.h"

@interface HCHelpViewDsiplay ()<UIScrollViewDelegate>

@end

@implementation HCHelpViewDsiplay

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBarHidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated
{
    self.navigationController.navigationBarHidden = NO;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    if(VERSION>=7.0)
        self.automaticallyAdjustsScrollViewInsets = NO;
    
    int height = self.view.frame.size.height;
    
    UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, height)];
    scroll.contentSize = CGSizeMake(320*3+5, height);
    scroll.showsHorizontalScrollIndicator=NO;
    scroll.showsVerticalScrollIndicator=NO;
    scroll.bouncesZoom=NO;
    scroll.pagingEnabled=YES;
    scroll.bounces=NO;
    scroll.delegate = self;
    scroll.pagingEnabled = YES;
    [self.view addSubview:scroll];
    
    for (int i = 0; i<3; i++)
    {
        UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(320*i, 0, 320, height)];
        NSString *imageNameStr = [NSString stringWithFormat:@"HCHelp%d.png",i];
        image.image = [UIImage imageNamed:imageNameStr];
        image.userInteractionEnabled = YES;
        [scroll addSubview:image];
        
        UIButton *close = [UIButton buttonWithType:UIButtonTypeCustom];
        close.frame = CGRectMake(280, 30, 30, 30);
        [close setBackgroundImage:[UIImage imageNamed:@"HCHelpClose.png"] forState:UIControlStateNormal];
        [close addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        [image addSubview:close];
    }
}

- (void)back
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
    if(scrollView.contentOffset.x > 320*2)
        [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
